package com.corpgovernment.organization.convert;

import com.corpgovernment.api.organization.bo.LandmarkBO;
import com.corpgovernment.api.organization.bo.SearchLandmarkRequestBO;
import com.corpgovernment.api.organization.model.org.base.LandmarkVO;
import com.corpgovernment.organization.entity.db.MbLandmark;
import com.ctrip.corp.obt.generic.utils.CollectionUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class LandmarkConvert {

	/**
	 * vo转do
	 *
	 * @param landmarkList
	 * @return
	 */
	public List<MbLandmark> convertFromVo(List<LandmarkVO> landmarkList) {
		if (CollectionUtils.isEmpty(landmarkList)) {
			return new ArrayList<>();
		}
		return landmarkList.stream().map(e -> {
			MbLandmark landmark = new MbLandmark();
			landmark.setId(e.getId());
			landmark.setOrgId(e.getOrgId());
			landmark.setCityCode(e.getCityCode());
			landmark.setCityName(e.getCityName());
			landmark.setAddress(e.getAddress());
			landmark.setLandmarkName(e.getLandmarkName());
			landmark.setLandmarkEnName(e.getLandmarkEnName());
			landmark.setLatitude(new BigDecimal(e.getLatitude()));
			landmark.setLongitude(new BigDecimal(e.getLongitude()));
			landmark.setRadius(e.getRadius());
			landmark.setIsDeleted(e.getIsDeleted());
			return landmark;
		}).collect(Collectors.toList());
	}

	/**
	 * 根据bo获取do
	 *
	 * @param request
	 * @return
	 */
	public MbLandmark convertFromBo(SearchLandmarkRequestBO request) {
		if (request == null) {
			return null;
		}
		MbLandmark landmark = new MbLandmark();
		landmark.setCityCode(request.getCityCode());
		landmark.setOrgId(request.getOrgId());
		return landmark;
	}

	/**
	 * do转bo
	 *
	 * @param landmarkList
	 * @return
	 */
	public List<LandmarkBO> convertToBo(List<MbLandmark> landmarkList) {
		if (CollectionUtils.isEmpty(landmarkList)) {
			return new ArrayList<>();
		}
		return landmarkList.stream().map(e -> {
			LandmarkBO landmark = new LandmarkBO();
			landmark.setAddress(e.getAddress());
			landmark.setLandmarkName(e.getLandmarkName());
			landmark.setLandmarkEnName(e.getLandmarkEnName());
			landmark.setLatitude(e.getLatitude());
			landmark.setLongitude(e.getLongitude());
			landmark.setRadius(e.getRadius());
			return landmark;
		}).collect(Collectors.toList());
	}

	/**
	 * do转vo
	 *
	 * @param landmarkList
	 * @return
	 */
	public List<LandmarkVO> convertToVo(List<MbLandmark> landmarkList) {
		if (CollectionUtils.isEmpty(landmarkList)) {
			return new ArrayList<>();
		}
		return landmarkList.stream().map(e -> {
			LandmarkVO landmark = new LandmarkVO();
			landmark.setId(e.getId());
			landmark.setOrgId(e.getOrgId());
			landmark.setCityCode(e.getCityCode());
			landmark.setCityName(e.getCityName());
			landmark.setAddress(e.getAddress());
			landmark.setLandmarkName(e.getLandmarkName());
			landmark.setLandmarkEnName(e.getLandmarkEnName());
			landmark.setLatitude(String.valueOf(e.getLatitude()));
			landmark.setLongitude(String.valueOf(e.getLongitude()));
			landmark.setRadius(e.getRadius());
			landmark.setIsDeleted(e.getIsDeleted());
			return landmark;
		}).collect(Collectors.toList());
	}
}
